#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 2e2 + 10, INF = 0x3f3f3f3f;

int n;
int a[N];
vector<pair<int, int>> b;
int f[N][N];

void solve()
{
    cin >> n;
    for (int i = 1;i <= n;i++) {
        cin >> a[i];
        a[i + n] = a[i];
    }
    b.push_back({ 0,0 });
    for (int i = 1;i < 2 * n;i++)
        b.push_back({ a[i],a[i + 1] });

    int n2 = b.size() - 1;
    for (int len = 2;len <= n;len++)
        for (int l = 1;l + len - 1 <= n2;l++) {
            int r = l + len - 1;
            for (int k = l;k < r;k++)
                f[l][r] = max(f[l][r], f[l][k] + f[k + 1][r] + b[l].first * b[k].second * b[r].second);
        }

    int ans = 0;
    for (int i = 1;i + n - 1 <= n2;i++)
        ans = max(ans, f[i][i + n - 1]);
    cout << ans;
}

signed main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    //cin>>T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}